public class Solution1041 {
    public boolean isRobotBounded(String instructions) {
        int x=0,y=0,d=0;
        int[] dx=new int[]{0,1,0,-1};
        int[] dy=new int[]{1,0,-1,0};
        for (int i=0;i<4;i++){
            for (char c : instructions.toCharArray()) {
                if (c=='L'){
                    d=(d+3)%4;
                }else if (c=='R'){
                    d=(d+1)%4;
                }else {
                    x=x+dx[d];
                    y=y+dy[d];
                }
            }
            if (x==0 && y==0){
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1041().isRobotBounded("GLRLGLLGLGRGLGL"));
    }
}
